from typing import Any, Dict, Type, get_type_hints

class BaseModel:
    def __init__(self, **kwargs):
        self._validate_and_set_fields(kwargs)

    def _validate_and_set_fields(self, data: Dict[str, Any]):
        hints = get_type_hints(self.__class__)
        for field, expected_type in hints.items():
            if field in data:
                value = data[field]
                if not isinstance(value, expected_type):
                    raise TypeError(f"Expected type {expected_type} for field '{field}', got {type(value)}")
                setattr(self, field, value)
            else:
                raise ValueError(f"Missing required field '{field}'")

    def __repr__(self):
        fields = ', '.join(f"{field}={getattr(self, field)!r}" for field in self.__annotations__)
        return f"{self.__class__.__name__}({fields})"

# 使用自定义的BaseModel
class Student(BaseModel):
    uid: str
    stuNum: str
    stuName: str

# 创建Student实例
student = Student(uid='1', stuNum='A001', stuName='Alice')
print(student)
